/*
 *    Copyright 2011-2012 The Hook Team
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.hook.yaksha.node;

import java.util.List;
import java.util.concurrent.BlockingQueue;

import org.hook.yaksha.config.MasterConfig;
import org.hook.yaksha.node.job.Job;
import org.hook.yaksha.node.job.JobMergedResult;
import org.hook.yaksha.node.job.JobTask;
import org.hook.yaksha.node.job.JobTaskResult;

/**
 * 任务结果合并接口，用于提供不同方式的结果合并
 * 
 * @author suwuqiang 2011-12-26
 */
public interface JobResultMerger extends Component<MasterConfig> {

	/**
	 * 用于Master的合并 合并某一个job的所有可以合并的结果，当前默认实现是多线程合并(主干只是单线程竞争合并)
	 * 
	 * @param job
	 * @param 分支队列 ，支持多个线程同时合并，不需要等待主干合并结束顺序化合并
	 * @param 需要合并的结果集合
	 * @param 是否需要合并的时候处理一些lazy的内容(基于entry的再次计算)
	 */
	public void merge(Job job, BlockingQueue<JobMergedResult> branchResultQueue, BlockingQueue<JobTaskResult> jobTaskResultsQueue,
			boolean needMergeLazy);

	/**
	 * 用于Slave的合并 合并某一个Task的多个结果
	 * 
	 * @param jobTask
	 * @param jobTaskResults
	 * @param needMergeLazy
	 * @return
	 */
	public JobTaskResult merge(JobTask jobTask, List<JobTaskResult> jobTaskResults, boolean needMergeLazy);
}
